package com.kadron.entity;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

import org.hibernate.validator.NotNull;

import com.kadron.base.KBase;

@Entity
@Table(name = "k_user_favorites", uniqueConstraints = { @UniqueConstraint(columnNames = {
		"user_id", "item_id" }) })
public class UserFavorites extends KBase implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8689013740715256364L;
	
	private Item item;
	private User user;

	public UserFavorites() {
		super();
	}

	public UserFavorites(Item item, User user) {
		this();
		this.item = item;
		this.user = user;
	}
	
	@NotNull
	@ManyToOne(targetEntity = Item.class)
	@JoinColumn(name = "item_id", nullable = false)
	public Item getItem() {
		return item;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	@NotNull
	@ManyToOne(targetEntity = User.class)
	@JoinColumn(name = "user_id", nullable = false)
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = super.hashCode();
		result = prime * result + ((item == null) ? 0 : item.hashCode());
		result = prime * result + ((user == null) ? 0 : user.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		UserFavorites other = (UserFavorites) obj;
		if (item == null) {
			if (other.item != null)
				return false;
		} else if (!item.equals(other.item))
			return false;
		if (user == null) {
			if (other.user != null)
				return false;
		} else if (!user.equals(other.user))
			return false;
		return true;
	}

	
}
